"""
@author: haha
@file: news_data.py
@time: 2023/3/10 0010 20:09:15
"""
from model import db


class Data(db.Model):
    __tablename__ = "datadb"
    id = db.Column(db.String(128), primary_key=True)
    ctime = db.Column(db.String(128), nullable=False)
    title = db.Column(db.TEXT, nullable=False)
    description = db.Column(db.TEXT, nullable=False)
    picUrl = db.Column(db.TEXT, nullable=False)
    url = db.Column(db.TEXT, nullable=False)
    # add_time      notice

    def keys(self):
        return ('id', 'ctime', 'title', 'description', 'picUrl', 'url')


    def __getitem__(self, item):
        return getattr(self, item)

    @classmethod
    def create_data(cls, id, ctime, title, description, picUrl, url):
        data = cls()  # 创建实例对象
        data.id = id
        data.ctime = ctime
        data.title = title
        data.description = description
        data.picUrl = picUrl
        data.url = url
        # user._password = generate_password_hash(value)
        # user._password = value
        db.session.add(data)
        db.session.commit()